﻿using Dapper;
using Dommel;
using SP.Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SP.EFcore.Repository
{
    public class Repository<T>:IRepository<T> where T : class
    {
        //protected readonly MyDbContext _db;
        //public Repository(MyDbContext db)
        //{
        //    _db = db;
        //}
      protected  DapperFactory _db = DapperFactory.GetInstance();

        public int Delete(T model)
        {
            using var conn = _db.GetDbConnection();
            return Convert.ToInt32(conn.Delete(model));
        }

        public List<T> GetList()
        {
            using var conn = _db.GetDbConnection();
            return conn.GetAll<T>().ToList();
        }

        public int Insert(T model)
        {
            using var conn = _db.GetDbConnection();
            return Convert.ToInt32(conn.Insert(model));
        }

        public int Update(T model)
        {
            using var conn = _db.GetDbConnection();
            return Convert.ToInt32(conn.Update(model));
        }
    }
}
